const baseUrl = "https://api-hmugo-web.itheima.net/api/public/v1"

class Request {
  request(api, param) {
    return new Promise((resolve, reject) => {
      uni.request({
        url: baseUrl + api,
        method: "GET",
        data: param,
        success: (res) => {
          const { message, meta } = res.data
          if (meta.status == 200) {
            resolve(message)
          } else {
            uni.showToast({
              title: meta.msg,
              icon: "error",
            })
          }
        },
        fail: (err) => {
          uni.showToast({
            title: err.errMsg,
            icon: "error",
          })
          reject(err)
        },
      })
    })
  }
}

const http = new Request()

export default http
